package com.loubii.sunshineSchool.util;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.widget.ImageView;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.http.GET;

public class ImageUtil {


    public interface getImage_Interface {

        @GET(".")
        Call<ResponseBody> getImage();

    }


    public static void downloadAvatar(String baseUrl, final ImageView view) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl+'/')
                .build();
        getImage_Interface getImage_interface = retrofit.create(getImage_Interface.class);

        Call<ResponseBody> avatarCall = getImage_interface.getImage();

        avatarCall.enqueue(new Callback<ResponseBody>() {

            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                Bitmap bitmap = BitmapFactory.decodeStream(responseBody.byteStream());
                view.setImageBitmap(bitmap);
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Log.d("downLoadImageWrong",t.getMessage());
            }

        });

    }
}
